package cn.edu.scau.dao;

import cn.edu.scau.entity.Dish;

import org.apache.ibatis.jdbc.SQL;

public class DishSqlProvider {

    public String insertSelective(Dish record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("dish");
        
        if (record.getDishid() != null) {
            sql.VALUES("dishID", "#{dishid,jdbcType=INTEGER}");
        }
        
        if (record.getDishname() != null) {
            sql.VALUES("dishName", "#{dishname,jdbcType=VARCHAR}");
        }
        
        if (record.getDishprice() != null) {
            sql.VALUES("dishPrice", "#{dishprice,jdbcType=DECIMAL}");
        }
        
        if (record.getDishmaterial() != null) {
            sql.VALUES("dishMaterial", "#{dishmaterial,jdbcType=VARCHAR}");
        }
        
        if (record.getDishtype() != null) {
            sql.VALUES("dishType", "#{dishtype,jdbcType=VARCHAR}");
        }
        
        if (record.getDishfeatures() != null) {
            sql.VALUES("dishFeatures", "#{dishfeatures,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Dish record) {
        SQL sql = new SQL();
        sql.UPDATE("dish");
        
        if (record.getDishname() != null) {
            sql.SET("dishName = #{dishname,jdbcType=VARCHAR}");
        }
        
        if (record.getDishprice() != null) {
            sql.SET("dishPrice = #{dishprice,jdbcType=DECIMAL}");
        }
        
        if (record.getDishmaterial() != null) {
            sql.SET("dishMaterial = #{dishmaterial,jdbcType=VARCHAR}");
        }
        
        if (record.getDishtype() != null) {
            sql.SET("dishType = #{dishtype,jdbcType=VARCHAR}");
        }
        
        if (record.getDishfeatures() != null) {
            sql.SET("dishFeatures = #{dishfeatures,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("dishID = #{dishid,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    
    
    public String findByNameTypeFeatures(String dishname,String dishtype,String dishfeatures){
    	SQL sql = new SQL();
    	sql.SELECT("dishID, dishName, dishPrice, dishMaterial, dishType, dishFeatures");
    	sql.FROM("dish");
    	if(dishname!=null) {
    		sql.WHERE(" dishName like concat('%',#{dishname},'%')");
    	}
    	if(dishtype!=null) {
    		sql.WHERE(" dishType like concat('%',#{dishtype},'%')");
    	}
    	if(dishfeatures!=null) {
    		sql.WHERE(" dishFeatures like concat('%',#{dishfeatures},'%')");
    	}
    	return sql.toString();
    }
}